package com.rongji.cms.tools.db;

import com.rongji.cms.tools.db.domain.MysqlColumnProp;
import com.rongji.cms.tools.db.domain.OracleColumnProp;
import com.rongji.cms.tools.db.domain.vo.DbInfoVo;
import com.rongji.cms.tools.db.strategy.DbStrategy;
import com.rongji.cms.tools.db.strategy.DbStrategyFactoryNotSpring;
import com.rongji.cms.tools.db.utils.DbCompareUtil;
import com.rongji.cms.tools.db.utils.DbResultUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author yang
 * @date 2023/1/29 13:55
 * @description 使用策略模式+工厂模式测试
 */

@Slf4j
public class DbStrategyTest {
    public static void main(String[] args) {

        String compareResult = testOracle();
//        String compareResult = testMysql();
//        DbResultUtil.writeToExcel();
//        DbResultUtil.writeToTxt(compareResult);

    }

    public static String testOracle() {
        DbInfoVo dbAInfo = new DbInfoVo();
        dbAInfo.setDbName("orcl");
        dbAInfo.setDbHost("192.168.118.77:1521");
        dbAInfo.setDbUsername("rjcmscs");
        dbAInfo.setDbPassword("rjcmscs123.");


        DbInfoVo dbBInfo = new DbInfoVo();
        dbBInfo.setDbName("orcl");
        dbBInfo.setDbHost("192.168.118.77:1521");
        dbBInfo.setDbUsername("rjcmsdevelop");
        dbBInfo.setDbPassword("rjcmsdevelop");


        String dbType = "oracle";

        DbStrategy dbStrategy = DbStrategyFactoryNotSpring.getByDbType(dbType);

        Map<String, Map<String, OracleColumnProp>> dbAMap = dbStrategy.getDBInfo(dbAInfo, OracleColumnProp.class);
        Map<String, Map<String, OracleColumnProp>> dbBMap = dbStrategy.getDBInfo(dbBInfo, OracleColumnProp.class);
        String compareResult = DbCompareUtil.compareDBInfo(dbAMap, dbBMap, OracleColumnProp.class);

        log.info(compareResult);
        return compareResult;
    }


    public static String testMysql() {

        DbInfoVo dbAInfo = new DbInfoVo();
        dbAInfo.setDbName("test1");
        dbAInfo.setDbHost("192.168.212.224:3306");
        dbAInfo.setDbUsername("root");
        dbAInfo.setDbPassword("123456");

        DbInfoVo dbBInfo = new DbInfoVo();
        dbBInfo.setDbName("test2");
        dbBInfo.setDbHost("192.168.212.224:3306");
        dbBInfo.setDbUsername("root");
        dbBInfo.setDbPassword("123456");


        String dbType = "mysql";

        DbStrategy dbStrategy = DbStrategyFactoryNotSpring.getByDbType(dbType);

        Map<String, Map<String, MysqlColumnProp>> dbAMap = dbStrategy.getDBInfo(dbAInfo, MysqlColumnProp.class);
        Map<String, Map<String, MysqlColumnProp>> dbBMap = dbStrategy.getDBInfo(dbBInfo, MysqlColumnProp.class);
        String compareResult = DbCompareUtil.compareDBInfo(dbAMap, dbBMap, MysqlColumnProp.class);

        log.info(compareResult);

        return compareResult;
    }
}
